﻿/**
 * class FlashHttpRequestManager
 */
package vsg.remote {
	
	import flash.external.ExternalInterface;
	import flash.utils.*;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;	
	/**
	 * construct the Http Request Defined 
	 */
	public class FlashHttpRequestExternalInterfaceManager {
		
		private var _httpRequest:FlashHttpRequest;
		

		
		private static var instance:FlashHttpRequestExternalInterfaceManager;

		/**
		 * handle flash response defined 
		 */
		private function flaReponseHandler(opt:Object):void {

			try {
				_httpRequest.request( opt );				
			} catch (error : Error) {
				trace(error);
			}

		}
		
		private function callback( resData ):void {
			/**
			 * invoke javascript call back defind 
			 */
			//ExternalInterface.call(debugCallJsFunction, resData);
			
			/**
			 * invoke call back
			 */
			//ExternalInterface.call(callJsFunction, resData);

		}
		
		public static function getInstance():FlashHttpRequestExternalInterfaceManager {

			if (instance == null) {
				instance = new FlashHttpRequestExternalInterfaceManager();
			}
			return instance;
		}
		
		
		
		public function externalInterface(httpRequest:FlashHttpRequest) {
			// defined inner http request 
			_httpRequest = httpRequest;
			// --- create the addCallback javascript ---
			if (ExternalInterface.available) {
				ExternalInterface.addCallback("sendAndLoad",flaReponseHandler);
			}

		}

		
	}
	
}